package com.listen.disruptor;

import java.util.Date;

import com.lmax.disruptor.EventTranslatorVararg;
import com.lmax.disruptor.RingBuffer;

/**
 * 使用translator方式到事件生产者发布事件
 * @author Administrator
 *
 */
public class LogEventProducerWithTranslator {
	
	private final static EventTranslatorVararg<LogEvent> translator = new EventTranslatorVararg<LogEvent>() {
		
		public void translateTo(LogEvent logEvent, long seq, Object... objs) {
			logEvent.setLogId((Long) objs[0]);
			logEvent.setContent((String) objs[1]);
			logEvent.setDate((Date) objs[2]);
		}
	};

	private final RingBuffer<LogEvent> ringBuffer;
	public LogEventProducerWithTranslator(RingBuffer<LogEvent> ringBuffer){
		this.ringBuffer = ringBuffer;
	}
	
	public void onData(long logId, String content, Date date){
		this.ringBuffer.publishEvent(translator, logId, content, date);
	}
}
